﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;

using Telerik.Web.UI;

public partial class Protegidos_Administracao_Cadastros__popup_acUploadContratoVigencia : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            trResultado.Visible = false;
        }
    }
    
    #region Eventos
    protected void btnGravar_Click(object sender, EventArgs e)
    {
        BindValidResults();
    }
    protected void btnFechar_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
        //if (e.CommandName == "Update")
        //{
        //    ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true);
        //}
        //else if (e.CommandName == "Insert")
        //{
        //    ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind('navigateToInserted');", true);
        //}
        //else
        //{
        //    ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelEdit();", true);
        //}
    }
    #endregion

    #region Metodos
    private void BindValidResults()
    {
        if (RadUpload1.UploadedFiles.Count > 0)
        {
            foreach (UploadedFile validFile in RadUpload1.UploadedFiles)
            {
                string nameFile = "CV_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".pdf";
                string targetFolder = Server.MapPath("~/FileTemp");
                validFile.SaveAs(Path.Combine(targetFolder, nameFile), true);
                Session.Add("ContratoName", nameFile);
                Session.Add("ContratoFile", validFile.GetName());
            }

            //OcultaCampos(true);

            labelNoResults.Visible = false;
            repeaterResults.Visible = true;
            repeaterResults.DataSource = RadUpload1.UploadedFiles;
            repeaterResults.DataBind();
        }
        else
        {
            labelNoResults.Visible = true;
            repeaterResults.Visible = false;
        }

        ExibeResultado();
    }
    private void OcultaCampos(bool oculta)
    {
        trResultado.Visible = !oculta;
        btnGravar.Visible = !oculta;
    }
    private void ExibeResultado()
    {
        trSeleciona.Visible = false;
        trResultado.Visible = true;
        trMsg.Visible = false;
        btnGravar.Visible = false;
    }
    #endregion
}
